//
//  ViewController.m
//  06-UINavigationController
//
//  Created by dllo on 16/7/21.
//  Copyright © 2016年 LST. All rights reserved.
//

#import "ViewController.h"
#import "PushTwoViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    // 设置 navigationBar 的属性
    // 1. title 标题 告诉用户, 我这个东西是干啥用的
    self.title = @"导航栏";
    self.navigationItem.title = @"高雅馨大SB";
    // 2.titleView 标题视图 附完view之后 title消失了 xy 对视图位置没有影响
    UISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:@[@"含蓄", @"王煌"]];
    seg.frame = CGRectMake(0, 0, 150, 44);
    self.navigationItem.titleView = seg;
    // 3.leftBarButtonItem
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStyleDone target:self action:@selector(comeBack:)];
    // 4.rightBarButtonItem
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add:)];
    // 5.leftBarButtonItems
    UIBarButtonItem *barButtonItemtitle = [[UIBarButtonItem alloc] initWithTitle:@"xxx" style:UIBarButtonItemStyleDone target:self action:@selector(clickItemTitle:)];
    UIBarButtonItem *barButtonSystemItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(SystemItem:)];
    self.navigationItem.leftBarButtonItems = @[barButtonItemtitle, barButtonSystemItem];
    // 7.隐藏 navigationBar YES隐藏NO不隐藏 默认NO
    // 下面两个是一样的
    self.navigationController.navigationBarHidden = NO;
    self.navigationController.navigationBar.hidden = NO;
    // 8. navigationBar背景样式 默认为UIBarStyleDefault 0
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    // 9.navigationBar的背景颜色
    self.navigationController.navigationBar.backgroundColor = [UIColor redColor];
    // 10.barTintColor Bar的颜色
    self.navigationController.navigationBar.barTintColor = [UIColor redColor];
    // 11.tintColor Bar上元素的颜色
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    // 12.translucent 管理半透明效果 YES为开启 NO为关闭
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
    btn.backgroundColor = [UIColor blueColor];
    btn.frame = CGRectMake(0, 0, 200, 200);
    [self.view addSubview:btn];
    
    // 设置为YES时, self.view坐标系从原点开始
    // 设置为NO, self.View坐标系从navigationBar下面开始
    // self.navigationController.navigationBar.translucent = NO;
    // 13.改变坐标系的效果, 与translucent为NO时效果一样
    self.edgesForExtendedLayout = UIRectEdgeNone;
    // 页面跳转相关
    // 1.入栈 pushViewcontroll
    // 2.出栈 viewControllers 获取到viewController里所有的控制器 pop
    // 3.self.navigationController.viewControllers
    // 4.topViewController栈顶视图控制器
    // 5.visibleViewController 可见视图控制器
    [btn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)comeBack:(UIBarButtonItem *)barButtonItem {
    NSLog(@"返回了");
}
- (void)add:(UIBarButtonItem *)add {
    
}
- (void)clickItemTitle:(UIBarButtonItem *)title {
    
}
- (void)SystemItem:(UIBarButtonItem *)item {
    
}
- (void)clickBtn:(UIButton *)sender {
    // 将视图控制器入栈
    [self.navigationController pushViewController:[[PushTwoViewController alloc] init] animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
